/**
 *
 */

package com.sq.partner.manager.util;

import java.io.BufferedReader;
import java.io.Reader;
import java.sql.Clob;


/**
 * @author X.Y.CHEN
 */
public class StrUtil {

    /**
     * 返回trim 后的String的值,null 返回空串
     *
     * @param o
     * @return
     */
    public static String getVal(Object o) {
        if (o == null) {
            return "";
        }
        return o.toString().trim();
    }

    public static String getValNoTrim(Object o) {
        if (o == null) {
            return "";
        }
        return o.toString();
    }

    /**
     * 获取邮箱前缀，@前面的
     *
     * @return 如果没有@符号 返回本身, 如果为null返回""
     */
    public static String getEmailPrefix(String email) {
        if (email == null) {
            return "";
        }
        int idxAt = email.lastIndexOf("@");
        if (idxAt > 0) {
            return email.substring(0, idxAt);
        } else {
            return email;
        }
    }

    /**
     * 判断字符串是否为空
     *
     * @param value 字符串
     * @return 空或空串返回true 否则false
     */
    public static boolean isEmpty(String value) {
        return (null == value || value.trim().equals("")) ? true : false;
    }
    public static boolean isEmpty(Long value) {
        return (null == value) ? true : false;
    }
    /**
     * 判断字符串是否为空
     *
     * @param value 字符串
     * @return 空或空串返回false 否则true
     */
    public static boolean isNotEmpty(String value) {
        return !isEmpty(value);
    }
    
    public static String ClobToString(Clob clob) throws Exception  {
	      String reString = "";
	      Reader is = clob.getCharacterStream();// 得到流
	      BufferedReader br = new BufferedReader(is);
	      String s = br.readLine();
	      StringBuffer sb = new StringBuffer();
	      while (s != null) {// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
		      sb.append(s);
		      s = br.readLine();
	      }
	      reString = sb.toString();
	      if(br!=null){
	          br.close();
	      }
	      if(is!=null){
	          is.close();
	      }
	      return reString;
    }
	public static String valueOf(Object var0) {
		return var0 == null ? "" : var0.toString();
	}
}
